package jp.seraph.same.view.gui.tree;

import javax.swing.tree.TreeNode;

import org.apache.commons.collections.Predicate;


public class TreeUtil {
    private TreeUtil(){

    }

    @SuppressWarnings("unchecked")
    public static <T extends TreeNode> T findNode(T aParent, Predicate aCondition){
        T tParent = aParent;
        Predicate tPredicate = aCondition;
        int tCount = tParent.getChildCount();
        for(int i=0; i<tCount; i++){
            T tChild = (T)tParent.getChildAt(i);
            if(tPredicate.evaluate(tChild))
                return tChild;
        }

        return null;
    }
}
